<?php

class Search_OptimizeController extends Zend_Controller_Action
{

    public function init()
    {
        Zend_Registry::get('layout')->setLayout('duty');
        
        $activeResource=Search_Model_Search::RESOURCE_NAME;
        
        // seting active resource
        Zend_Registry::set('resource',$activeResource);

        $this->view->headTitle()->append(Zend_Registry::get('locale')->_('Search'));
        
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
        $this->view->flash_messages = $this->_flashMessenger->getMessages();
        
        ini_set('max_execution_time',0);
    }

    public function indexAction()
    {
        if (!Zend_Registry::get('user')->canManage())
        {
            return $this->_response->setRedirect(Zend_Registry::get('view')->fixUrl('search'));
        }
        
        
        $search=new Search_Model_Search();
        
        $search->optimize();
        
        $this->_helper->FlashMessenger(Zend_Registry::get('locale')->_('Index was optimized'));
        return $this->_response->setRedirect(Zend_Registry::get('view')->fixUrl('search'));
    }


}

